<script setup>
import { useCartStore } from '@/stores/cartStore.js'
const cartStore = useCartStore()
const singleCheck = (item, selected) => {
  cartStore.singCheckChange(item.skuId, selected)
}
</script>

<template>
  <div class="app-cart">
    <div class="container">
      <!--面包屑-->
      <div class="bread-group">
        <el-breadcrumb separator=">">
          <el-breadcrumb-item :to="{path:'/'}">首页</el-breadcrumb-item>
          <el-breadcrumb-item>购物车</el-breadcrumb-item>
        </el-breadcrumb>
        <!--<div class="bread-item"><RouterLink to="/">首页</RouterLink></div>
        <i class="iconfont icon-angle-right"></i>
        <div class="bread-item"><RouterLink>购物车</RouterLink></div>-->
      </div>
      <!--列表-->
      <div class="cart">
        <table>
          <thead>
            <tr>
              <th width="120">
                <el-checkbox :model-value="cartStore.isAll" @change="cartStore.allCheckChange($event)">全选</el-checkbox>
              </th>
              <th width="400">商品信息</th>
              <th width="220">单价</th>
              <th width="180">数量</th>
              <th width="180">小计</th>
              <th width="140">操作</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="item in cartStore.cartList" :key="item.id">
              <td>
                <el-checkbox :model-value="item.selected" @change="(selected) => singleCheck(item, selected)" />
              </td>
              <td>
                <div class="goods">
                  <RouterLink to="/"><img :src="item.picture" alt="" /></RouterLink>
                  <div>
                    <p class="name ellipsis">
                      {{ item.name }}
                    </p>
                  </div>
                </div>
              </td>
              <td class="tc">
                <p>&yen;{{ item.price }}</p>
              </td>
              <td class="tc">
                <el-input-number :min="1" v-model="item.count" />
              </td>
              <td class="tc">
                <p class="f16 red">&yen;{{ (item.price * item.count).toFixed(2) }}</p>
              </td>
              <td class="tc">
                <p>
                  <el-popconfirm
                    title="确认删除吗?"
                    confirm-button-text="确认"
                    cancel-button-text="取消"
                    @confirm="cartStore.delCart(item.skuId)"
                  >
                    <template #reference>
                      <a href="javascript:;">删除</a>
                    </template>
                  </el-popconfirm>
                </p>
              </td>
            </tr>
            <tr v-if="cartStore.cartList.length === 0">
              <td colspan="6">
                <div class="cart-none">
                  <el-empty description="购物车列表为空">
                    <el-button type="primary">随便逛逛</el-button>
                  </el-empty>
                </div>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
      <!-- 操作栏 -->
      <div class="action">
        <div class="batch">
          共 {{ cartStore.allCount }} 件商品，已选择 {{ cartStore.SelectedCount }} 件，商品合计：
          <span class="red">¥ {{ cartStore.SelectedCPrice }}</span>
        </div>
        <div class="total">
          <el-button size="large" type="primary" @click="$router.push('/checkout')">下单结算</el-button>
        </div>
      </div>
      <!--猜你喜欢-->
    </div>
  </div>
</template>

<style lang="scss" scoped>
.app-cart{
  padding-bottom: 40px;
  .bread-group{
    display: flex;
    align-items: center;
    padding: 25px 0;
    .iconfont{
      font-size: 12px;
      margin-left: 5px;
      margin-right: 5px;
      line-height: 22px;
    }
    a:hover{
      color: $xtxColor;
    }
    :deep() {
      .el-breadcrumb__separator{
        font-family: monospace;
      }
    }
  }
  .cart{
    background-color: #fff;
    color: #666;
    table {
      border-spacing: 0;
      border-collapse: collapse;
      line-height: 24px;
      th,
      td{
        padding: 10px;
        border-bottom: 1px solid #f5f5f5;
        &:first-child {
          text-align: left;
          padding-left: 30px;
          color: #999;
        }
      }
      th{
        font-size: 16px;
        font-weight: normal;
        line-height: 50px;
      }
    }
  }
  .cart-none{
    text-align: center;
    padding: 120px 0;
    background: #fff;
    p {
      color: #999;
      padding: 20px 0;
    }
  }
  .tc{
    text-align: center;
    a{
      color: $xtxColor;
    }
    .xtx-numbox{
      margin: 0 auto;
      width: 120px;
    }
  }
  .red{
    color: $priceColor;
  }
  .green{
    color: $xtxColor;
  }
  .f16{
    font-size: 16px;
  }
  .goods{
    display: flex;
    align-items: center;
    img{
      width: 100px;
      height: 100px;
    }
    > div{
      width: 280px;
      font-size: 16px;
      padding-left: 10px;
      .attr{
        font-size: 14px;
        color: #999;
      }
    }
  }
  .action{
    display: flex;
    background: #fff;
    margin-top: 20px;
    height: 80px;
    align-items: center;
    font-size: 16px;
    justify-content: space-between;
    padding: 0 30px;
    .xtx-checkbox{
      color: #999;
    }
    .batch{
      a {
        margin-left: 20px;
      }
    }
    .red{
      font-size: 18px;
      margin-right: 20px;
      font-weight: bold;
    }
  }
  .tit{
    color: #666;
    font-size: 16px;
    font-weight: normal;
    line-height: 50px;
  }
}
</style>